package top.simonby.iron.plugin.data.jpa;

import lombok.Data;
import org.springframework.data.annotation.CreatedDate;
import org.springframework.data.annotation.LastModifiedDate;
import org.springframework.data.jpa.domain.AbstractPersistable;
import org.springframework.data.jpa.domain.support.AuditingEntityListener;

import javax.persistence.Column;
import javax.persistence.EntityListeners;
import javax.persistence.MappedSuperclass;
import javax.persistence.Version;
import java.io.Serializable;
import java.time.LocalDateTime;


/**
 * @author 91223
 */
@Data
@MappedSuperclass
@EntityListeners(AuditingEntityListener.class)
public abstract class BaseJpaEntity<PK extends Serializable> extends AbstractPersistable<PK> implements Serializable {

    /**
     * 创建用户
     */
    protected String createBy;

    @CreatedDate
    @Column(updatable = false, nullable = false)
    protected LocalDateTime createTime = LocalDateTime.now();

    /**
     * 更新人
     */
    protected String updateBy;
    @LastModifiedDate
    @Column(nullable = false)
    protected LocalDateTime updateTime = LocalDateTime.now();

    /**
     * 数据权限
     */
    @Column
    protected String tenantId = "system";

    /**
     * 删除标记 1=已删除,0=未删除
     */
    @Column
    protected Integer delFlag = 1;
    /**
     * 数据权限
     */
    protected String dataScope;
    /**
     * 版本号
     */
    @Version
    protected Integer reVersion = 1;

}
